package com.smalls.redshoes.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint.FontMetricsInt;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.TextView;

public class PaddingTextView extends TextView {
    private boolean adjustTopForAscent = true;
    FontMetricsInt fontMetricsInt;

    public PaddingTextView(Context context) {
        super(context);
    }

    public PaddingTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PaddingTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    protected void onDraw(Canvas canvas) {
        if (this.adjustTopForAscent) {
            if (this.fontMetricsInt == null) {
                this.fontMetricsInt = new FontMetricsInt();
                getPaint().getFontMetricsInt(this.fontMetricsInt);
            }
            canvas.translate(0.0f, (float) (this.fontMetricsInt.top - this.fontMetricsInt.ascent));
        }
        super.onDraw(canvas);
    }
}
